package com.itheima.health.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.itheima.health.dao.MemberDao;
import com.itheima.health.pojo.Member;
import com.itheima.health.service.MemberService;
import com.itheima.health.utils.MD5Utils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;

/**
 * @author ：seanyang
 * @date ：Created in 2019/6/13
 * @description ：会员业务实现类
 * @version: 1.0
 */
@Service
public class MemberServiceImpl  implements MemberService {

	@Autowired
	private MemberDao memberDao;

	@Transactional
	@Override
	public void add(Member member) {
		if (member.getPassword() != null){
			member.setPassword(MD5Utils.md5(member.getPassword()));
		}
		memberDao.add(member);
	}
	@Override
	public Member findByTelephone(String telephone) {
		return memberDao.findByTelephone(telephone);
	}

	@Override
	public List<Integer> findMemberCountByMonth(List<String> monthList) {
		List<Integer> memberCountList = new ArrayList<>();
		for (String month : monthList){
			month = month + ".31"; // yyyy.mm.31
			Integer count = memberDao.findMemberCountBeforeDate(month);
			memberCountList.add(count);
		}
		return memberCountList;
	}
}
